import {HTTP} from '../utility/HTTP.js'

class requestModel extends HTTP{ 
  getLatest(callBack){
    this.request({
      url: '/classic/latest',
      success:(res)=>{
        callBack(res)
        this._setStorage(res.index)
      }
    })
  }
  upDate(value, callBack){
    if (this._getValue(value)){
      callBack(this._getValue(value))
    }else{
    this.request({
      url: '/classic/index=' + value,
      success: (res) => {
        callBack(res)
        console.log(res)
        this._createKey(res.index,res)
      }
    })
    }
  }
  isNext(index){
    return index == 1?true:false
  }
  isPrevious(index){
    let value = this._getStorage()
    return index<=value-1?false:true
  }
  _setStorage(index){
    wx.setStorageSync(
      'index',index
    )
  }
  _getStorage(){
    let value = wx.getStorageSync('index')
    return value
  }
  _createKey(index,data){
    wx.setStorageSync('key'+index, data)
  }
  _getValue(index){
    return wx.getStorageSync('key'+index)
  }
};
class upVote extends HTTP {
  setlike(bihevior,artId,type){
    let url = bihevior=='like'?'/like':'/like/cancel'
    this.request({
      url: '/like',
      method:'POST',
      data:{
        art_id:artId,
        type: type
      }
    })
  }
}

export {requestModel,upVote}